//
//  ZDDStatusCell.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/6/27.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit
import SnapKit
let StautsMargin: CGFloat = 10
class ZDDStatusCell: UITableViewCell {
    //记录约束
    var toolBarTopConstraint:Constraint?
    var status:ZDDStatuses?{
        didSet{
        statusOriginalView.status = status
            //卸载约束
            toolBarTopConstraint?.uninstall()
            if status?.retweeted_status == nil{
            
                statusRetweetView.hidden = true
                statusToolbar.snp_makeConstraints(closure: { (make) -> Void in
                    toolBarTopConstraint = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
            
            }else{
            
                statusRetweetView.status = status
                statusRetweetView.hidden = false
                statusToolbar.snp_makeConstraints(closure: { (make) -> Void in
                    toolBarTopConstraint = make.top.equalTo(statusRetweetView.snp_bottom).constraint
                })
                
            }
            statusToolbar.status = status
        }
    }
    

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: -  设置视图
    private func setupUI(){

        backgroundColor = RBG(237,green: 237,blue: 237)

        
        //添加控件

       contentView.addSubview(statusOriginalView)
       contentView.addSubview(statusToolbar)
       contentView.addSubview(statusRetweetView)
        
        
        //添加约束
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(contentView).offset(10)
//            make.height.equalTo(50)
        }
        //转发微博
        statusRetweetView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(statusOriginalView.snp_bottom)
//            make.height.equalTo(100)
        }
    // 底部toolbar（转发评论赞）
        statusToolbar.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(35)
           toolBarTopConstraint = make.top.equalTo(statusRetweetView.snp_bottom).constraint
        }
//
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(statusToolbar.snp_bottom)
        }
        
    
    }
    
    private lazy var statusOriginalView:ZDDStatusOriginalView = ZDDStatusOriginalView()
    // 底部toolbar（转发评论赞）
    private lazy var statusToolbar:ZDDStatusToolbar = ZDDStatusToolbar()
    
    //妆发微博
    private lazy var statusRetweetView:ZDDStatusRetweetView = ZDDStatusRetweetView()

}



















